package cn.com.surker.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FloorParserUtil {
    public static List<String> parseFloors(String input) {
        List<String> result = new ArrayList<>();
        Pattern rangePattern = Pattern.compile("(\\d+)[~-](\\d+)", Pattern.CASE_INSENSITIVE);

        // 去掉/之前的字符
        String floorInfo = input.substring(input.indexOf("/") + 1);

        Matcher matcher = rangePattern.matcher(floorInfo.toUpperCase().replaceAll("F", ""));
        if (matcher.find()) {
            int startFloor = Integer.parseInt(matcher.group(1));
            int endFloor = Integer.parseInt(matcher.group(2));

            // 确保startFloor小于等于endFloor
            int tempStart = Math.min(startFloor, endFloor);
            int tempEnd = Math.max(startFloor, endFloor);

            for (int i = tempStart; i <= tempEnd; i++) {
                result.add(i + "F");
            }
        } else {
            // 如果没有找到'-'或者'~', 直接处理单个楼层
            String singleFloor = floorInfo.replaceAll("[^\\d]", "") + "F";
            result.add(singleFloor);
        }

        return result;
    }

    public static void main(String[] args) {
        List<String> list = Arrays.asList("1#/3F", "1#/4-6F", "1#/4f-6f", "1#/3f", "1#/4~6F", "1#/4f~6f");
        for (String input : list) {
            List<String> floors = parseFloors(input);
            System.out.println(floors); // 应输出对应的楼层列表
        }
    }
}
